import Mock from 'mockjs'

const Random = Mock.Random

let listData = []

for (let i = 0; i < 100; i++) {
    let item = {
        name: Random.cname(),
        avatar: Random.dataImage('50x50', '头像'),
        date: Random.date()
    }
    listData.push(item)
}

Mock.mock('/api/list', 'post', (res) => {
    let request = JSON.parse(res.body)
    let [page, size, total] = [request.page, request.size, listData.length]
    let len = total / size
    let totalPages = len - parseInt(len) > 0 ? parseInt(len) + 1 : len
    let respones = listData.slice(page * size, (page + 1) * size)
    return {
        code: 200,
        data: {
            lists: respones,
            page: {
                total_page: totalPages,
                current_page: page,
                total: total
            }
        },
        message: '请求成功'
    }
})

export default Mock
